//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/.
// 			VisualNovelToolkit		     /_/_/_/_/_/_/_/_/_/.
// Copyright ©2013 - Sol-tribe.	/_/_/_/_/_/_/_/_/_/.
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/.
using UnityEngine;
using System.Collections;

/// <summary>
/// ViNo GUI text event listener.
/// </summary>
[ ExecuteInEditMode ]
[ AddComponentMenu( "ViNo/Event/GuiTextEvent" ) ]
public class ViNoGuiTextEventListener : ViNoTextEventListener{
	public GUISkin skin;
	public Rect messageRect = new Rect( 50 , 280 , 854 , 300 );
	public bool fitToScreenWidth;
	public bool fitToScreenHeight;

	public string theText;

	void Start(){}

	public override void Enabled(){				
		if( ! Application.isPlaying ){
			CommitChanges();
		}
	}

	/// <summary>
	/// Raises the update text event.
	/// </summary>
	/// <param name='theText'>
	/// The text.
	/// </param>
	public override void OnUpdateText( string theText){
		SetTextMeshText( theText );
	}

	/// <summary>
	/// Raises the text set event.
	/// </summary>
	/// <param name='theText'>
	/// The text.
	/// </param>
	public override void OnTextSet( string theText ){
		SetTextMeshText( theText );
	}

	public override void OnDisplayedText(){
		base.OnDisplayedText();
	}
	
	void OnGUI(){
		if( skin != null ){
			GUI.skin = skin;
		}
		if( fitToScreenWidth ){
			messageRect.width = Screen.width;
		} 

		if( fitToScreenHeight ){
			messageRect.height = Screen.height;
		} 

		GUI.Label( messageRect , this.theText );

		GUI.skin = null;
	}

	private void SetTextMeshText( string theText ){
		this.theText = theText;//GetColoredString( m_BaseColHexStr , theText , hasPromptImageLast );
	}

}

